﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using EasySL.Entity;

namespace EasySL.UI.Controls
{
    public partial class ProductEdit : UserControl
    {
        public Product Product { get; set; }
        public List<Category> Categorys { get; set; }
        
        public ProductEdit()
        {
            InitializeComponent();

            this.Product = new Product();
            this.Categorys = new List<Category>();

            this.Loaded += new RoutedEventHandler(ProductEdit_Loaded);           
        }

        void ProductEdit_Loaded(object sender, RoutedEventArgs e)
        {            
            this.DataContext = this.Product;
            this.categoryList.ItemsSource = this.Categorys;

            if (this.Product.Id == 0 && this.Categorys.Count > 0)
            {
                this.categoryList.SelectedIndex = 0;
                return;
            }
            
            foreach (Category category in Categorys)
            {
                if (category.CategoryName == Product.Category.CategoryName)
                {
                    this.categoryList.SelectedItem = category;
                    break;
                }
            }

        }
    }
}
